package com.yonyou.cyxdms.basedata.service.controller.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.basedata.client.domains.vo.ModelCacheVO;
import com.yonyou.cyxdms.basedata.service.service.model.ModelService;
import com.yonyou.cyxdms.basedata.service.vo.CarparamInfoVO;
import com.yonyou.cyxdms.basedata.service.vo.GroupCarparamInVO;
import com.yonyou.cyxdms.basedata.service.vo.VsProductDlrVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 车型
 *
 * @author renwd
 * @since 2018/12/11
 */

@RestController
@RequestMapping("/model")
public class ModelController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(ModelController.class);

    @Autowired
    private ModelService modelService;

    /**
     * 按条件查询车型信息
     *
     * @param queryParam
     * @return java.util.List<com.yonyou.cyxdms.basedata.client.domains.DTO.basedata.ModelCacheVO>
     * @author renwd
     * @since 2018/12/11
     */
    @GetMapping(value = "/queryModelByCondition")
    public List<ModelCacheVO> queryModelByCondition(@RequestParam Map<String, Object> queryParam) {
        return modelService.queryModelByCondition(queryParam);
    }

    /**
     * 根据车系id查询查询车型信息
     *
     * @param seriesId
     * @return java.util.List<com.yonyou.cyxdms.basedata.client.domains.DTO.basedata.ModelCacheVO>
     * @author guorp
     * @since 2018/12/13
     */
    @GetMapping(value = "/getModelBySeriesId")
    public List<ModelCacheVO> getModelBySeriesId(@RequestParam Long seriesId) {
        return modelService.getModelBySeriesId(seriesId);
    }

    /**
     * @description：查询所有车型
     * @author ：quankk
     * @date ：Created in 2019/1/15 15:22
     * @modified By：
     */
    @ApiOperation(value = "查询所有车型", notes = "查询所有车型")
    @GetMapping(value = "/allModel", produces = "application/json")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header"
            , value = "用户")})
    public List<ModelCacheVO> allModel() {
        return modelService.allModel();
    }

    /**
     * 车型分页信息
     *
     * @author dengqiang
     * @since 2018/12/25
     */
    @GetMapping(value = "/caparamInfo", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(notes = "车型分页信息", value = "车型分页信息")
    public IPage<CarparamInfoVO> queryCarparamInfo(@RequestParam("brandId") Long brandId,
                                                   @RequestParam("carserialId") Long carserialId, @RequestParam(
            "pageNum") Long pageNum,
                                                   @RequestParam("pageSize") Long pageSize) {

        logger.info("brandId:{}", brandId);
        logger.info("carserialId:{}", carserialId);

        return modelService.queryCarparamInfo(brandId, carserialId, pageNum, pageSize);
    }

    /**
     * 根据车型ID列表查询车型名称
     *
     * @author dengqiang
     * @since 2018/12/25
     */
    @GetMapping(value = "/queryCarparamNames", produces = {"application/json;" +
            "charset=UTF-8"})
    public List<String> queryCarparamNames(@RequestParam(value = "carparamIdS", required =
            true) String carparamIdS) {

        List<String> carparamNames = new ArrayList<>();
        carparamNames.add("todo");
        //遍历车型id,查询车型,给carparamNames设置车型名称
        return carparamNames;
    }

    /**
     * 根据车系ID列表查询车型信息
     * 使用于  海报、线索
     *
     * @author dengqiang
     * @since 2019/1/7
     */
    @GetMapping(value = "/queryCarparamInVO", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(notes = "车型信息", value = "车型信息")
    public List<GroupCarparamInVO> queryCarparamInVO(@RequestParam("carserialId") Long carserialId) {
        logger.info("carserialId:{}", carserialId);
        return modelService.queryCarparamInfo(carserialId);
    }

    /**
     * 通过车型名称与appid查询车型id
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/9/6
     */
    @GetMapping("/queryModelBynameAndAppid")
    public Long queryModelBynameAndAppid(@RequestParam("appId") String appId,
                                         @RequestParam("modelName") String modelName) {
        return modelService.queryModelBynameAndAppid(appId, modelName);
    }


    /**
     * JK获取id与code映射数据
     *
     * @param:
     * @return: 车型全字段数据
     * @auther: tanjie
     * @since: 2019/9/10
     */
    @GetMapping("/queryModelMapping")
    public List<Map<String, Object>> queryModelMapping(@RequestParam("appId") String appId) {
        return modelService.queryModelMapping(appId);
    }

    /**
     * 获取所有车型接口
     * 未登陆接口
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/10/8
     */
    @GetMapping("/getAllByAppId")
    public Map<Object, Object> getAll(HttpServletRequest request, @RequestParam(value = "requestId",
            required = false) String requestId, @RequestParam(value = "recordTime", required = false) Long recordTime) {

        String appId = request.getHeader("appId");
        return modelService.getAllByAppId(appId, requestId, recordTime);
    }

    /**
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/11/4
     */
    @GetMapping("/getAllModelByAppId")
    public List<ModelCacheVO> getAllModelByAppId(@RequestParam("appId") String appId) {
        return this.modelService.getAllModelByAppId(appId);
    }

    /**
     * 根据车型code获取车型信息
     * @param:
     * @return:
     * @auther: zjy
     * @since: 2019/11/4
     */
    @GetMapping("/getModelNew")
    public VsProductDlrVO getModelNew(@RequestParam("modelCode") String modelCode,@RequestParam("appId") String appId) {
        return this.modelService.getModelNew(modelCode,appId);
    }
}
